(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

open XNum
open UTypes
open SymbolTable
open Lexer
  
(*
  Priorities:

   2 right ||
   3 right &&
   4 non   == <> > < >= <=
   5 left  land lor lxor lsr lsl
   6 left  + -
   7 left  * / mod
   8 left  ^
   9 left  function application
  11 right prefix operations
  12 left  postfix operations

*)
type pattern =
  | PAnything
  | PId of symbol
  | PNumber of num
  | PChar of uc_char
  | PSymbol of symbol
  | PTuple of pattern list
  | PList of pattern list
  | PListTail of pattern list * pattern
  | PAssign of symbol * pattern

type term =
  | TUnbound
  | TId of symbol
  | TNumber of num
  | TChar of uc_char
  | TSymbol of symbol
  | TApp of term * term list
  | TTuple of term list
  | TList of term list
  | TListTail of term list * term
  | TFun of ((pattern list) * (term option) * term) list
  | TLocal of decl list * term
  | TSequence of stmt list * term
  | TDo of stmt list
  | TIfThenElse of term * term * term
  | TMatch of term * (pattern * (term option) * term) list
  and decl =
  | DFun of symbol * pattern list * term option * term
  | DPattern of pattern * term
  and stmt =
  | SEquation of term * term
  | SIfThen of term * stmt
  | SIfThenElse of term * stmt * stmt
  | (*| SForce of array term*)
  SFunction of term

val parse_program : lexer -> decl list
  
val parse_expression : lexer -> term
  

